﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using BusinessClass.JsonClass;
using Newtonsoft.Json;

namespace BusinessClass
{
    //public class LogHelper
    //{
    //    const string MakedImgState = "makedTxtToImg";
    //    const string CuttedState = "cutted:";
    //    const string NotCutConfigSate = "notCutConfig:";
    //    public LogHelper(string fileName)
    //    {
    //        var log = File.ReadAllText(fileName);
    //        MakedTxtToImg = log.Contains(MakedImgState);

    //        var ptn = "cutted:{(.+?)}";

    //        var m = Regex.Match(log, ptn, RegexOptions.Singleline);
    //        var c = m.Captures[1];
    //        CuttedImgs = c.Value.Trim()
    //            .Split(new string[] { "\r\n" }
    //                , StringSplitOptions.RemoveEmptyEntries);

    //        ptn = "notCutConfig:{(.+?)}";
    //        m = Regex.Match(log, ptn, RegexOptions.Singleline);
    //        c = m.Captures[1];
    //        NotCuttedImgs = c.Value.Trim()
    //            .Split(new string[] { "\r\n" }
    //                , StringSplitOptions.RemoveEmptyEntries);

    //    }
    //    public bool MakedTxtToImg;
    //    public string[] CuttedImgs;
    //    public string[] NotCuttedImgs;
    //    private static string toString(string[] strs)
    //    {
    //        return strs.Aggregate((a, b) => string.Format("{0}\r\n{1}", a, b));
    //    }
    //    public static void MakeLog(string fileName, bool makedTxtToImg, string[] cuttedImgs, string[] notCuttedImgs)
    //    {
    //        File.WriteAllText(fileName,
    //            (makedTxtToImg == true ? MakedImgState : "") +
    //            CuttedState + "{" + toString(cuttedImgs) + "}" +
    //            NotCutConfigSate + "{" + toString(notCuttedImgs) + "}");
    //    }

    //    public static void MakeLog(string fileName)
    //    {
    //        MakeLog(fileName, MakedTxtToImgStore, CuttedImgsStore.ToArray(), NotCuttedImgsStore.ToArray());
    //    }
    //    public static bool MakedTxtToImgStore;
    //    public static List<string> CuttedImgsStore = new List<string>();
    //    public static List<string> NotCuttedImgsStore = new List<string>();
    //    public static void MakeOne(string cuttedImg)
    //    {
    //        CuttedImgsStore.Add(cuttedImg);
    //    }
    //    public static void SaveOne(string notCuttedImg)
    //    {
    //        NotCuttedImgsStore.Add(notCuttedImg);
    //    }
    //}
    public class LogHelper
    {
        private string WorkingDir { get; set; }
        public LogHelper(string dir)
        {
            WorkingDir = dir;
        }
        public void Log(LogJson log)
        {
            var logpath = Common.conbindPath(WorkingDir, "log.json");

            var txt = JsonConvert.SerializeObject(log);
            File.WriteAllText(logpath, txt);

        }
    }
}
